<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .top{
            position: fixed;
            bottom: 20px;
            right: 20px;
        }
        body{
            height: 3000px;
        }
    </style>
</head>
<body>
    <div id="app">
        <home-index></home-index>  
    
    </div>
</body>
<script src="./vue.js"></script>
<script>
    const backtop={
        inserted:function(el,res){
            el.style.display='none'
            window.onscroll=function(){
                const scolltop=document.documentElement.scrollTop||document.body.scrollTop
                if(scolltop>200){
                    el.style.display='block'
                }else{
                    el.style.display='none'
                }
            }
            
            el.onclick=()=>{
                window.scrollTo(0,0)
            }
        }
    }
    const HomeIndex={
        template:`
            <button class="top" v-backtop='200'>回到顶端</button>
        `,
        directives:{
            backtop
        }
    }
    Vue.component('HomeIndex',HomeIndex)
    const vm =new Vue({
        el:'#app',
        
       
    })
</script>
</html>